<template>
  <div>
    <a-form :form="form" style="max-width: 500px; margin: 40px auto 0;">
      <a-form-item
        label="模型"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
      >
        <a-select v-decorator="['model', { initialValue: 'yolov10n', rules: [{required: true, message: '请选择'}] }]">
          <a-select-option value="yolov10b">yolov10b</a-select-option>
          <a-select-option value="yolov10l">yolov10l</a-select-option>
          <a-select-option value="yolov10m">yolov10m</a-select-option>
          <a-select-option value="yolov10n">yolov10n</a-select-option>
          <a-select-option value="yolov10s">yolov10s</a-select-option>
          <a-select-option value="yolov10x">yolov10x</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item
        label="训练周期"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        class="stepFormText"
      >
        <a-input type="number" v-decorator="['epoch', { initialValue: 3, rules: [{required: true, message: '请输入'}] }]"/>
      </a-form-item>
      <a-form-item
        label="训练批次"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
      >
        <a-input type="number" v-decorator="['batch', { initialValue: 16, rules: [{required: true, message: '请输入'}] }]"/>
      </a-form-item>
      <a-form-item
        label="优化器"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
      >
        <a-select v-decorator="['optimizer', { initialValue: 'auto', rules: [{required: true, message: '请选择'}] }]">
          <a-select-option value="auto">auto</a-select-option>
          <a-select-option value="SGD">SGD</a-select-option>
          <a-select-option value="Adam">Adam</a-select-option>
          <a-select-option value="AdamW">AdamW</a-select-option>
          <a-select-option value="NAdam">NAdam</a-select-option>
          <a-select-option value="RAdam">RAdam</a-select-option>
          <a-select-option value="RMSProp">RMSProp</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item
        label="初始学习率"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
      >
        <a-input type="number" v-decorator="['lr0', { initialValue: 0.01, rules: [{required: true, message: '请输入'}] }]"/>
      </a-form-item>
      <a-form-item
        label="最终学习率参数"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
      >
        <a-input type="number" v-decorator="['lrf', { initialValue: 0.01, rules: [{required: true, message: '请输入'}] }]"/>
      </a-form-item>
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
        <a-button style="margin-right: 8px" @click="prevStep">上一步</a-button>
        <a-button :loading="loading" type="primary" @click="nextStep">提交</a-button>
      </a-form-item>
    </a-form>r
  </div>
</template>

<script>
export default {
  name: 'Step2',
  data () {
    return {
      labelCol: { lg: { span: 6 }, sm: { span: 5 } },
      wrapperCol: { lg: { span: 18 }, sm: { span: 19 } },
      form: this.$form.createForm(this),
      loading: false,
      timer: 0
    }
  },
  methods: {
    nextStep () {
      const that = this
      const { form: { validateFields } } = this
      that.loading = true
      validateFields((err, values) => {
        if (!err) {
          console.log('表单 values', values)
          that.timer = setTimeout(function () {
            that.loading = false
            that.$emit('nextStep')
          }, 1500)
        } else {
          that.loading = false
        }
      })
    },
    prevStep () {
      this.$emit('prevStep')
    }
  },
  beforeDestroy () {
    clearTimeout(this.timer)
  }
}
</script>

<style lang="less" scoped>
  .stepFormText {
    margin-bottom: 24px;

    .ant-form-item-label,
    .ant-form-item-control {
      line-height: 22px;
    }
  }

</style>
